package com.itshare.video.mapper;

import com.itshare.video.pojo.po.Category;
import com.itshare.video.pojo.po.CategoryExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.session.RowBounds;

public interface CategoryMapper {
    long countByExample(CategoryExample example);

    int deleteByExample(CategoryExample example);

    @Delete({
        "delete from t_category",
        "where category_id = #{categoryId,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long categoryId);

    @Insert({
        "insert into t_category (REVISION, CREATED_BY, ",
        "CREATED_TIME, UPDATED_TIME, ",
        "category_name, delete_status, ",
        "parent_id)",
        "values (#{revision,jdbcType=INTEGER}, #{createdBy,jdbcType=VARCHAR}, ",
        "#{createdTime,jdbcType=TIMESTAMP}, #{updatedTime,jdbcType=TIMESTAMP}, ",
        "#{categoryName,jdbcType=VARCHAR}, #{deleteStatus,jdbcType=INTEGER}, ",
        "#{parentId,jdbcType=INTEGER})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="categoryId", before=false, resultType=Long.class)
    int insert(Category record);

    int insertSelective(Category record);

    List<Category> selectByExampleWithRowbounds(CategoryExample example, RowBounds rowBounds);

    List<Category> selectByExample(CategoryExample example);

    @Select({
        "select",
        "category_id, REVISION, CREATED_BY, CREATED_TIME, UPDATED_TIME, category_name, ",
        "delete_status, parent_id",
        "from t_category",
        "where category_id = #{categoryId,jdbcType=BIGINT}"
    })
    @ResultMap("com.itshare.video.mapper.CategoryMapper.BaseResultMap")
    Category selectByPrimaryKey(Long categoryId);

    int updateByExampleSelective(@Param("record") Category record, @Param("example") CategoryExample example);

    int updateByExample(@Param("record") Category record, @Param("example") CategoryExample example);

    int updateByPrimaryKeySelective(Category record);

    @Update({
        "update t_category",
        "set REVISION = #{revision,jdbcType=INTEGER},",
          "CREATED_BY = #{createdBy,jdbcType=VARCHAR},",
          "CREATED_TIME = #{createdTime,jdbcType=TIMESTAMP},",
          "UPDATED_TIME = #{updatedTime,jdbcType=TIMESTAMP},",
          "category_name = #{categoryName,jdbcType=VARCHAR},",
          "delete_status = #{deleteStatus,jdbcType=INTEGER},",
          "parent_id = #{parentId,jdbcType=INTEGER}",
        "where category_id = #{categoryId,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Category record);
}